package ntd.remote.link;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.remote.link.enums.EnumRemoteOpt;
import ntd.remote.online.ComOnline;
import ntd.remote.online.bo.OnlineInfo;

public class ActionRemoteMsgReturn extends ActionAbs {

    public static final String ACTION_MSG_RETURN = "action-msg-return";

    @Override
    public ActionInfo info() {
        return new ActionInfo("客户端返回消息处理action", ACTION_MSG_RETURN, this);
    }

    @Override
    public ActionOutBo handle() {
        OnlineInfo onlineInfo = ComOnline.getOnlineInfo("appInfo", actionInBo.getDataCode());
        JSONObject extendField = onlineInfo.getExtendField();
        String dataStr = actionInBo.getDataStr();
        if (JSONUtil.isTypeJSON(dataStr)) {
            extendField.putOpt(EnumRemoteOpt.SERVICE_RES.getCode() + "-" + ACTION_MSG_RETURN, JSONUtil.parse(dataStr));
        } else {
            extendField.putOpt(EnumRemoteOpt.SERVICE_RES.getCode() + "-" + ACTION_MSG_RETURN, dataStr);
        }
        ComOnline.online("appInfo", onlineInfo);
        return new ActionOutBo();
    }
}
